package Two;

import java.util.Comparator;
import java.util.Arrays;
import java.util.Scanner;

//class AgeComparator implements Comparator<PersonSortable2>{
//
//	public int compare(PersonSortable2 o1, PersonSortable2 o2) {
//		
//		return o1.getAge()-o2.getAge();
//	}
//}
//class NameComparator implements Comparator<PersonSortable2>{
//
//	public int compare(PersonSortable2 o1,PersonSortable2 o2) {
//		
//		return o1.getName().compareTo(o2.getName());
//	}
//
//}
class PersonSortable2 {
	public PersonSortable2(String name, int age) {
		super();
		this.name = name;
		this.age = age;
	}

	private String name;
	private int age;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	@Override
	public String toString() {
		return name + "-" + age;

	}

}

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		PersonSortable2[] p = new PersonSortable2[n];
		for (int i = 0; i < n; i++) {
			p[i] = new PersonSortable2(scan.next(), scan.nextInt());
		}
		Comparator<PersonSortable2> n1 = (PersonSortable2 o1, PersonSortable2 o2) -> (o1.getName().compareTo(o2.getName()));  
//		Comparator<PersonSortable2> n1 = new Comparator<PersonSortable2>() {
//			public int compare(PersonSortable2 o1, PersonSortable2 o2) {
//
//				return o1.getAge() - o2.getAge();
//			}
//		};
		Comparator<PersonSortable2> n2 = (PersonSortable2 o1, PersonSortable2 o2) -> (o1.getAge() - o2.getAge());  
		Arrays.sort(p, n1);
		System.out.println("NameComparator:sort");
		for (int i = 0; i < n; i++) {
			System.out.println(p[i]);
		}
//		Comparator<PersonSortable2> n2 = new Comparator<PersonSortable2>() {
//			public int compare(PersonSortable2 o1, PersonSortable2 o2) {
//
//				return o1.getName().compareTo(o2.getName());
//			}
//		};
		Arrays.sort(p, n2);
		System.out.println("AgeComparator:sort");
		for (int i = 0; i < n; i++) {
			System.out.println(p[i]);
		}
		System.out.println(Arrays.toString(n1.getClass().getInterfaces()));
		System.out.println(Arrays.toString(n2.getClass().getInterfaces()));
		scan.close();
	}
}
